﻿using System;
using System.Collections.Generic;
using System.Web.UI;
using FluentTests.Framework;
using FluentTests.NUnit;
using FluentTests.Framework.VerbExtensions;
using NUnit.Framework;

namespace FluentTests.Tests
{
    [TestFixture]
    public class CollectionsTestUsingNUnit
    {
        

        [Test]
        public void TestEmptyCollectionIsEmpty()
        {
            Ensure.That(new List<string>()).Is.Empty();
        }

        [Test]
        [ExpectedException(typeof(AssertionException))]
        public void TestEmptyCollectionIsNotEmpty()
        {
            Ensure.That(new List<string>()).Is.Not.Empty();
        }

        [Test]
        public void TestNonEmptyCollectionIsNonEmpty()
        {
            Ensure.That(new List<string>() { "" }).Is.Not.Empty();
        }

        [Test]
        [ExpectedException(typeof(AssertionException))]
        public void TestNonEmptyCollectionIsEmpty()
        {
            Ensure.That(new List<string>() { "" }).Is.Empty();
        }
    
        [Test]
        public void TestListIsNotEmptyUsingVerbs()
        {
            var list = new List<string>()
                           {
                               "Not empty collection"
                           };
            Ensure.That(list).Is.Not.Empty();
        }

        [Test]
        [ExpectedException(typeof(AssertionException))]
        public void TestListIsEmptyFailsUsingVerbs()
        {
            var list = new List<string>() { "Not empty" };
            Ensure.That(list).Is.Empty();
        }

        [Test]
        [ExpectedException(typeof(AssertionException))]
        public void TestListIsNotEmptyFailsUsingVerbs()
        {
            var list = new List<string>();
            Ensure.That(list).Is.Not.Empty();
        }

        [Test]
        public void TestAllItemsInCollectionIsOfSameType()
        {
            Ensure.That(new List<object>() { "a", "b" }).Are.AllOfSameType();
        }

        [Test]
        [ExpectedException(typeof(AssertionException))]
        public void TestAllItemsInCollectionIsOfSameTypeFailes()
        {
            Ensure.That(new List<object>() { "a", 5 }).Are.AllOfSameType();
        }
    
       
        [Test]
        public void TestListIsEmptyUsingVerbs()
        {
            var list = new List<string>();
            Ensure.That(list).Is.Empty();
        }

        [Test]
        public void TestItemCountGreaterThan()
        {
            var list = new List<string>(){"","",""};
            Ensure.That(list).Has.MoreElementsThan(2);
        }

        [Test]
        public void TestItemCountLessThan()
        {
            var list = new List<string>(){""};
            Ensure.That(list).Has.LessElementsThan(2);
        }

        [Test]
        public void TestItemCount()
        {
            var list = new List<string>() { "" };
            Ensure.That(list).Has.ElementCount(1);
        }

        [Test]
        [ExpectedException(typeof(AssertionException))]
        public void TestItemCountFails()
        {
            var list = new List<string>() { "" };
            Ensure.That(list).Has.ElementCount(2);
        }

        [Test]
        public void TestItemCountUsingLambda()
        {
            var list = new List<string>() { "" };
            Func<string, bool> f = x => x.Length > 2;
            Ensure.ThatEnumerable(list).Where(a => a.EndsWith("")).Has.Not.ElementCount(2);
        }

        [Test]
        public void TestAny()
        {
            var list = new List<string>() { "" };
            Func<string, bool> f = x => x.Length > 2;
            Ensure.ThatEnumerable(list).Has.Any(a => a.EndsWith(""));
        }

        [Test]
        public void TestNotAny()
        {
            var list = new List<string>() { "" };
            Func<string, bool> f = x => x.Length > 2;
            Ensure.ThatEnumerable(list).Has.Not.Any(a => a.EndsWith("33"));
        }

        [Test]
        [ExpectedException(typeof(AssertionException))]
        public void TestAnyFails()
        {
            var list = new List<string>() { "" };
            Func<string, bool> f = x => x.Length > 2;
            Ensure.ThatEnumerable(list).Has.Not.Any(a => a.EndsWith(""));
        }

        [Test]
        [ExpectedException(typeof(AssertionException))]
        public void TestNotAnyFails()
        {
            var list = new List<string>() { "33" };
            Func<string, bool> f = x => x.Length > 2;
            Ensure.ThatEnumerable(list).Has.Not.Any(a => a.EndsWith("33"));
        }

        [Test]
        public void TestEveryItemMeetsCondition()
        {
            var list = new List<string>(){ "55", "55" };
            Ensure.That(list).Has.ValidForAll(a => a == "55");
        }

        [Test]
        [ExpectedException(typeof(AssertionException))]
        public void TestEveryItemDoesNotMeetsCondition()
        {
            var list = new List<string>() { "55", "33" };
            Ensure.That(list).Has.ValidForAll(a => a == "55");
        }

        [Test]
        public void TestHasElements()
        {
            var list = new List<string>() { "55", "33" };
            Ensure.That(list).Has.Elements();
        }

        [Test]
        [ExpectedException(typeof(AssertionException))]
        public void TestHasElementsThrowsException()
        {
            var list = new List<string>() {};
            Ensure.That(list).Has.Elements();
        }

    }
}
